import { Component, OnInit, Injector } from '@angular/core';
import { NgZorroPageBaseComponent } from '../../../core/ng-zorro-page-base-component/ng-zorro-page-base-component.component';
import { CityListComponent } from '../../school/cityList';
import { Router, ActivatedRoute, Params } from '@angular/router';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import {
  PagedResultDto, ClassInfoOutput, PagerSearchInput, HttpService, BaseComponentConfig,
  CustomNavigation, KeyValueOutput, SearchValue
} from '../../..';
@Component({
  selector: 'app-schooledit',
  templateUrl: './schooledit.component.html',
  styleUrls: ['./schooledit.component.scss']
})

export class SchooleditComponent implements OnInit {
  selectedProvince;
  selectedCity;
  schoolName = "";
  cityData: any;
  provinceData: any;
  listEntitiesdata: any;
  editid;
  resute;
  constructor(injecter: Injector,
    private router: Router,
    private message: NzMessageService,
    private activatedRoute: ActivatedRoute,
    public http: HttpService) {
    const city = new CityListComponent;
    this.provinceData = city.provinceDatas;
    this.cityData = city.cityDatas;




  }

  ngOnInit() {
    this.activatedRoute.queryParams.subscribe(
      data => this.editid = (data['smId']));

    this.http.get<any>("School/GetSchool?input=" + this.editid).then(e => {
      this.listEntitiesdata = e;
      this.schoolName = this.listEntitiesdata.schoolName;
      this.selectedProvince = this.listEntitiesdata.address[0];
      this.selectedCity = this.listEntitiesdata.address[1];
    });
  }
  provinceChange() {

  }
  async serve(type: string) {

    const that = this;
    that.resute = [];
    const address = this.selectedProvince + "," + this.selectedCity;
    const data = {
      "schoolName": this.schoolName, "id": this.editid, "address": address
    };


    if (!this.schoolName || !this.selectedProvince || !this.selectedCity) {
      that.message.info('请填写完整');
      return false;
    } else {

      await that.http.post<any>("School/UpdateSchool", data);

      this.message.create(type, `保存成功`);

      this.router.navigate(['app/management']);

    }

  }
}
